import redis

class Myredis():
    def __init__(self):
        self.redis = redis.Redis(host='localhost',port=6379)

    #储存redis
    def setexcode(self,mobile,time,x):
        self.redis.setex(mobile,time,x)
    
    #获取redis值
    def getcode(self,mobile):
        value = self.redis.get(mobile)
        if value:
            value = str(self.redis.get(mobile),encoding='utf8')
        # print(value)
        return value
    
r = Myredis()   
# r.setexcode('123',30,1456)     
# print(r.getcode('123'))